package cn.tedu;

import java.sql.*;

public class Demo3 {
    public static void main(String[] args) throws SQLException {
        Connection conn = DriverManager.getConnection(
                "jdbc:mysql://localhost:3307/empdb?characterEncoding=utf8&serverTimezone=Asia/Shanghai&useSSL=false",
                "root","0616");
        Statement s = conn.createStatement();
//        s.execute("create table jdbc1(id int primary key auto_increment,age int,name varchar(20))");
//        s.execute("insert into jdbc1 values(null,20,'周姣'),(null,18,'zhoujiao')");
//        s.executeUpdate("insert into emp (name) values ('tom')");
//        s.executeUpdate("update emp set name='jerry' where name='tom'");
//        s.executeUpdate("delete from emp where name='jerry'");
        ResultSet resultSet = s.executeQuery("select name,sal from emp;");
        // 遍历结果集中的数据
        while (resultSet.next()) {
            // 获取游标指向的这条数据的某个字段的值,通过字段名获取
//            String name = resultSet.getString("name");
//            double sal = resultSet.getDouble("sal");
            // 通过查询回来数据的位置来获取数据
            String name = resultSet.getString(1);
            double sal = resultSet.getDouble(2);
            System.out.println(name+":"+sal);
        }
        conn.close();
        System.out.println("执行完毕");
    }
}
